package org.example.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.example.entity.CommonResult;
import org.example.entity.LoginInfo;
import org.example.entity.User;
import org.example.service.UserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


@RestController
@Api(tags = "用户管理")
@RequestMapping("/security")
public class UserController {

	@Resource
	private UserService userService;

	@PostMapping("/login")
	@ApiOperation(value = "用户登录", notes = "返回token")
	public CommonResult<Object> login(@RequestBody LoginInfo loginInfo) {
		return userService.login(loginInfo);
	}

	@PostMapping("/user")
	@ApiOperation(value = "用户注册", notes = "返回注册结果")
	public CommonResult<Integer> register(@RequestBody User user) {
		return userService.register(user);
	}

	@PutMapping("/user")
	@ApiOperation(value = "修改用户信息", notes = "返回修改结果")
	public CommonResult<Integer> updateUser(@RequestBody User user) {
		return userService.updateUser(user);
	}

	@PostMapping("/logout")
	@ApiOperation(value = "用户注销", notes = "请求头中需要带上token")
	public CommonResult<String> logout() {
		return userService.logout();
	}
}
